package cn.edu.java.io.outputstream;

import java.io.FileOutputStream;
import java.io.IOException;

public class FileOutputStreamDemo {
    public static void main(String[] args) {
        String data = "Hello, World!";

        try (FileOutputStream fos = new FileOutputStream("output/abc.txt")) {
            // 将字符串转换为字节数组
            byte[] bytes = data.getBytes();

            // 写入字节数组到文件
            fos.write(bytes);

            System.out.println("数据成功写入文件。");
        } catch (IOException e) {
            System.out.println("写入文件时发生错误：" + e.getMessage());
        }
    }
}

